home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / ada / dat2txt.ada < prev    next >
Text File  |  1988-03-25  |  2KB  |  56 lines

  1. -- DAT2TXT.ADA   Ver. 1.00   25-MAR-1988
  2. -- Copyright 1988 John J. Herro
  3. -- Software Innovations Technology
  4. -- 1083 Mandarin Drive NE, Palm Bay, FL 32905-4706   (407)951-0233
  5. --
  6. -- Run this program on a PC before installing ADA-TUTR on another computer.
  7. -- It translates ADA-TUTR.DAT to TUTOR.TXT, a text file that can be easily
  8. -- transferred to other computers.  Then compile and run TXT2DAT.ADA on the
  9. -- other machine to create ADA-TUTR.DAT from TUTOR.TXT.
  10. --
  11. --
  12. with DIRECT_IO, TEXT_IO;
  13. procedure DAT2TXT is
  14.    subtype BLOCK_SUBTYPE is STRING(1 .. 64);
  15.    package RANDOM_IO is new DIRECT_IO(BLOCK_SUBTYPE);
  16.    DATA_FILE  : RANDOM_IO.FILE_TYPE;                         -- The input file.
  17.    TEXT_FILE  : TEXT_IO.FILE_TYPE;                          -- The output file.
  18.    BLOCK      : BLOCK_SUBTYPE;             -- A block of 64 bytes being copied.
  19.    OK         : BOOLEAN := TRUE;     -- True when both files open successfully.
  20.    LEGAL_NOTE : constant STRING(1 .. 30) := " Copyright 1988 John J. Herro ";
  21.                          -- LEGAL_NOTE isn't used by the program, but it causes
  22.                          -- the compiler to place this string in the .EXE file.
  23. begin
  24.    begin
  25.       RANDOM_IO.OPEN(DATA_FILE, RANDOM_IO.IN_FILE, NAME => "ADA-TUTR.DAT");
  26.    exception
  27.       when RANDOM_IO.NAME_ERROR =>
  28.          TEXT_IO.PUT_LINE(
  29.               "I'm sorry.  The file ADA-TUTR.DAT seems to be missing.");
  30.          OK := FALSE;
  31.    end;
  32.    begin
  33.       TEXT_IO.CREATE(TEXT_FILE, NAME => "TUTOR.TXT");
  34.    exception
  35.       when others =>
  36.          TEXT_IO.PUT_LINE("I'm sorry.  I can't seem to create TUTOR.TXT.");
  37.          TEXT_IO.PUT_LINE("Perhaps that file already exists?");
  38.          OK := FALSE;
  39.    end;
  40.    if OK then
  41.       while not RANDOM_IO.END_OF_FILE(DATA_FILE) loop
  42.          RANDOM_IO.READ(DATA_FILE, ITEM => BLOCK);
  43.          for I in BLOCK'RANGE loop
  44.             if BLOCK(I) = ASCII.CR then
  45.                BLOCK(I) := '~';
  46.             elsif BLOCK(I) = ASCII.LF then
  47.                BLOCK(I) := '^';
  48.             end if;
  49.          end loop;
  50.          TEXT_IO.PUT_LINE(FILE => TEXT_FILE, ITEM => BLOCK);
  51.       end loop;
  52.    end if;
  53.    TEXT_IO.PUT_LINE("TUTOR.TXT created.");
  54. end DAT2TXT;
  55.  
  56.